package com.nfit.web.others;

import com.nfit.entity.vo.ResponeVo;
import com.nfit.service.OthersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import static com.nfit.entity.vo.ResponeVo.fail;
import static com.nfit.entity.vo.ResponeVo.success;

@RestController
public class OthersController {
    @Autowired
    private OthersService othersService;

    @PostMapping("/others/sendMessage")
    public ResponeVo sendMessage(@RequestBody String message) {
        if (message == null || message.isEmpty()) {
            return fail("发送失败，消息不能为空");
        }
        othersService.sendMessage(message);
        return success("发送成功");
    }

    @GetMapping("/others/getMessage")
    public ResponeVo getMessage() {
        String message = othersService.getMessage(null);
        if (message!= null) {
            System.out.println("message: " + message);
            return success(message);
        }
        return fail("暂无消息");
    }
}
